package cn.nxcoder.jmw.controller.activemq;

import cn.nxcoder.jmw.core.JsonResult;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Topic;

/**
 * @author xiaqing
 */
@RestController
@Api(tags = "ActiveMQ-Topic模式请求接口")
@RequestMapping("/activemq/topic")
public class Pulisher {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Topic topic;

    private static final Logger LOG = LoggerFactory.getLogger(Pulisher.class);

    /**
     * 发送消息
     *
     * @param msg 待发送的消息
     */
    @GetMapping("/sendMsg/{msg}")
    public JsonResult<Void> sendMessage(@PathVariable(value = "msg") String msg) {
        jmsMessagingTemplate.convertAndSend(topic, msg);
        LOG.info("Topic发送消息：{}", msg);
        return new JsonResult<>();
    }
}
